home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: deallocTransPages.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:56:02 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "latch.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "bf_macro.h"
- #include "volume.h"
- #include "openlog.h"
- #include "trans.h"
- #include "page.h"
- #include "bitmap.h"
- #include "deallocinfo.h"
- #include "io_extfuncs.h"
- #include "trans_extfuncs.h"
- #include "bf_extfuncs.h"
- #include "bm_extfuncs.h"
- #include "bm_globals.h"
- #include "io_globals.h"
-
-
- /*
- * This function traverses the list of pages to deallocate and
- * sets the bitmap bit to free the page. For each bitmap
- * page the number of bits changed is remembered.
- *
- * NOTE: This code does not obtain any semaphores on the bitmap
- * pages since they are fixed in the buffer pool and this
- * function makes no call which would cause it to block.
- */
-
- int
- deallocTransPages (
-
- TRANSREC *transRec,
- LIST *pendingBitmapList
- )
- {
-
- PAGEDEALLOCINFO *currPage;
- PAGE2SIZE page2size;
- PAGECONTEXT *currBitmapPage;
- PID bitmapPid;
- VOLREC *volRec;
- int index;
-
-
- TRACE(TR_TRANS, TR_LEVEL_1);
-
-
- /*
- * See if there is any work to be done;
- */
- currPage = (PAGEDEALLOCINFO*) FIRST_LIST_ELEMENT(&(transRec->pageDeallocList));
- if (currPage == NULL) {
- SM_ASSERT(LEVEL_3, LIST_EMPTY(pendingBitmapList));
- return(esmNOERROR);
- }
-
- SM_ASSERT(LEVEL_3, !LIST_EMPTY(pendingBitmapList));
-
- /*
- * Initialize locals
- */
- currBitmapPage = (PAGECONTEXT*) FIRST_LIST_ELEMENT(pendingBitmapList);
- SM_ASSERT(LEVEL_1, currBitmapPage != NULL);
-
- /*
- * Process each chunk of pages
- */
- while ((currPage = (PAGEDEALLOCINFO*) listDeq(&(transRec->pageDeallocList))) != NULL) {
-
- CHECK_PAGEDEALLOCINFO_MAGIC(currPage);
- page2size = currPage->page2size;
-
- /*
- * Deallocate each physical page
- */
- for (index = 0; index < BLOCKCOUNT(page2size); index++) {
-
- /*
- * calculate the page that the bit to set lies on
- */
- bitmapPid.page = BIT_TO_PAGE(currPage->pid.page + index);
- bitmapPid.volid = currPage->pid.volid;
-
- /*
- * If we're not currently looking at the correct
- * bitmap page info, find it.
- */
- if (!PIDEQ(bitmapPid, currBitmapPage->pid)) {
- currBitmapPage = (PAGECONTEXT*) FIRST_LIST_ELEMENT(pendingBitmapList);
- while (currBitmapPage != NULL) {
- if (PIDEQ(bitmapPid, currBitmapPage->pid)) {
- /* the page is the one we want */
- break;
- }
- currBitmapPage = (PAGECONTEXT*) NEXT_LIST_ELEMENT(&(currBitmapPage->list));
- }
- SM_ASSERT(LEVEL_3, currBitmapPage!=NULL);
- }
-
- /*
- * Make sure the page isn't already marked free,
- * then mark it free and update the count of bits set
- */
- SM_ASSERT(LEVEL_3, !bm_CheckSet((UFOUR *) currBitmapPage->groupLink->bufFrame, (FOUR) BIT_IN_PAGE(currPage->pid.page + index)));
- bm_SetBit((UFOUR *) currBitmapPage->groupLink->bufFrame, (FOUR) BIT_IN_PAGE(currPage->pid.page + index));
- currBitmapPage->bitsChanged++;
-
- }
-
- /*
- * Remove the page from the buffer and
- * Return the page info to the Pool
- */
- bf_InvalidatePage(&(currPage->pid));
- poolEnq(&PageDeallocInfoPool, &(currPage->list));
- }
-
- /*
- * traverse the pendingBitmaplist and decrement the volhdr free
- * count by the number of pages deallocated. also decrement the
- * pendingOpCount for the volhdr and the bitmap page and unfix the
- * bitmap page . Then return the bitmap page context to the pool
- */
- while ((currBitmapPage = (PAGECONTEXT*) listDeq(pendingBitmapList)) != NULL) {
- /*
- * find the volume header,
- * increment the number of free pages
- * decrement the number of pending operations for it
- */
- volRec = io_FindVolRec(currBitmapPage->pid.volid);
- if (volRec == NULL) {
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
- if (waitSemaphore(&(volRec->headerLink->pageHash->semaphore)) != esmNOERROR) {
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
- io_ChangeVolFreePages(volRec, currBitmapPage->bitsChanged);
- volRec->headerLink->pageHash->pendingOpCount--;
- signalSemaphore(&(volRec->headerLink->pageHash->semaphore));
-
- /*
- * Remove the pending operation on the bitmap page,
- * unfix it, and return it to the pool
- */
- currBitmapPage->groupLink->pageHash->pendingOpCount--;
- bf_UnfixPage(currBitmapPage->groupLink, BF_DEFAULT, TRUE);
- poolEnq(&PageContextPool, &(currBitmapPage->list));
- }
-
- SM_ASSERT(LEVEL_3, io_CheckAllVolumes() == esmNOERROR);
- return(esmNOERROR);
- }
-